#include "thread.h"

int removedir(int netfd,sharInfo_t *sharInfo,MYSQL * mysql){
    
    printf("removedir begin\n");
    char sql[1024]={0};
    int check;
    bzero(sql,sizeof(sql));
    train_t recMsg;
    bzero(&recMsg,sizeof(train_t));
    recv(netfd, &recMsg.length, sizeof(int),MSG_WAITALL);
    recv(netfd, recMsg.buf, recMsg.length,MSG_WAITALL);
    remove_trailing_invisible_chars(recMsg.buf);
    strcpy(sql,recMsg.buf);
    printf("sql = %s\n",sql);

    int ret=checkDir(sharInfo,mysql,sql,NULL);
    printf("checkDir over\n");
    if(ret==-1){
        check=-1;
        send(netfd,&check,sizeof(int),MSG_NOSIGNAL);
        return -1;
    }

    char path[1024];
    bzero(path,sizeof(path));
    get_pwd(sharInfo,mysql,path);
    strcat(path,sql);

    printf("path = %s\n",path);
    char order[1024];
    sprintf(order,"update df_mes set tomb = 1 where path like '%s%%' and user='%s'and tomb=0",path,sharInfo->user);
    printf("order = %s\n",order);
    
    ret=mysql_query(mysql,order);
    if(ret != 0){
        fprintf(stderr,"mysql_query:%s\n", mysql_error(mysql));
        return -1;
    }

    check=0;
    send(netfd,&check,sizeof(int),MSG_NOSIGNAL);

    return 0;
}
    


    

